using System.ComponentModel.DataAnnotations;

namespace SG3L_RAG.Application.DTOs
{
    public class UserDto
    {
        public Guid Id { get; set; }
        public string Username { get; set; } = string.Empty;
        public string Email { get; set; } = string.Empty;
        public string PhoneNumber { get; set; } = string.Empty;
        public string Role { get; set; } = string.Empty;
        public DateTime CreatedAt { get; set; }
    }

    public class CreateUserDto
    {
        [Required(ErrorMessage = "用户名不能为空")]
        [StringLength(50, MinimumLength = 3, ErrorMessage = "用户名长度必须在3-50个字符之间")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "密码不能为空")]
        [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度必须在6-100个字符之间")]
        public string Password { get; set; } = string.Empty;

        [Required(ErrorMessage = "邮箱不能为空")]
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string Email { get; set; } = string.Empty;

        [Phone(ErrorMessage = "手机号格式不正确")]
        public string PhoneNumber { get; set; } = string.Empty;

        [Required(ErrorMessage = "角色不能为空")]
        public string Role { get; set; } = string.Empty;
    }

    public class UpdateUserDto
    {
        [Required(ErrorMessage = "用户名不能为空")]
        [StringLength(50, MinimumLength = 3, ErrorMessage = "用户名长度必须在3-50个字符之间")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "邮箱不能为空")]
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string Email { get; set; } = string.Empty;

        [Phone(ErrorMessage = "手机号格式不正确")]
        public string PhoneNumber { get; set; } = string.Empty;

        [Required(ErrorMessage = "角色不能为空")]
        public string Role { get; set; } = string.Empty;
    }

    public class CreateUserLegacyDto
    {
        [Required(ErrorMessage = "用户名不能为空")]
        [StringLength(50, MinimumLength = 3, ErrorMessage = "用户名长度必须在3-50个字符之间")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "密码不能为空")]
        [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度必须在6-100个字符之间")]
        public string Password { get; set; } = string.Empty;

        [Required(ErrorMessage = "邮箱不能为空")]
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string Email { get; set; } = string.Empty;

        [Required(ErrorMessage = "角色不能为空")]
        public string Role { get; set; } = string.Empty;
    }

    public class UpdatePhoneNumberDto
    {
        [Required(ErrorMessage = "手机号不能为空")]
        [Phone(ErrorMessage = "手机号格式不正确")]
        public string PhoneNumber { get; set; } = string.Empty;
    }

    public class UpdateEmailDto
    {
        [Required(ErrorMessage = "邮箱不能为空")]
        [EmailAddress(ErrorMessage = "邮箱格式不正确")]
        public string Email { get; set; } = string.Empty;
    }

    public class ChangePasswordDto
    {
        [Required(ErrorMessage = "新密码不能为空")]
        [StringLength(100, MinimumLength = 6, ErrorMessage = "密码长度必须在6-100个字符之间")]
        public string NewPassword { get; set; } = string.Empty;
    }

    public class CheckPasswordDto
    {
        [Required(ErrorMessage = "密码不能为空")]
        public string Password { get; set; } = string.Empty;
    }

    public class UpdateAvatarDto
    {
        public string? Avatar { get; set; } = string.Empty;
    }

    public class ValidateCredentialsDto
    {
        [Required(ErrorMessage = "用户名不能为空")]
        public string Username { get; set; } = string.Empty;

        [Required(ErrorMessage = "密码不能为空")]
        public string Password { get; set; } = string.Empty;
    }

    public class UserPermissionDto
    {
        public Guid Id { get; set; }
        public Guid DocumentId { get; set; }
        public string PermissionType { get; set; } = string.Empty;
        public DateTime GrantedAt { get; set; }
    }

    public class UserWithDetailsDto : UserDto
    {
        public int DocumentCount { get; set; }
        public int ConversationCount { get; set; }
        public int PermissionCount { get; set; }
        public List<UserPermissionDto> Permissions { get; set; } = new();
    }
}
